﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Lib.Utils;

namespace MS.INV.Reports.Qtys
{
    public partial class Qty_ByTime : Lib.Bases.Forms.BaseForm
    {
        public Qty_ByTime()
        {
            InitializeComponent();

            dtTuNgay.EditValue = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            dtDenNgay.EditValue = DateTime.Now;
        }

        private void btRef_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (Cvert.ToBoolean(chk.EditValue, false)) grid.Name = "grid_detail";
                else grid.Name = "grid";

                grid.SetData(DBLayer.ExecDataTable("Rpt_QtyByTime", "Command,TuNgay,DenNgay",
                    (!Cvert.ToBoolean(chk.EditValue, false)) ? "Summary" : "Detail",
                    Cvert.ToShortDate(Convert.ToDateTime(dtTuNgay.EditValue)),
                    Cvert.ToShortDate(Convert.ToDateTime(dtDenNgay.EditValue))));
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Load data");
            }
        }

        private void btPrint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string Name = (!Cvert.ToBoolean(chk.EditValue, false)) ? "Qty_ByTime.repx" : "Qty_ByTime_Detail.repx";
            Lib.Bases.Reports.ShowReport(Name, grid.GetFilteredDataSource(), "TuNgay,DenNgay",
                    Convert.ToDateTime(dtTuNgay.EditValue).ToString("dd/MM/yyyy"),
                    Convert.ToDateTime(dtDenNgay.EditValue).ToString("dd/MM/yyyy"));
        }

        private void btClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}
